/*
Building a Clean and Loyal State: The Strategic Dilemma of an Anti-corruption Campaign Under One-Party Rule
Authors: Tianyang Xi, Yang Yao and Qian Zhang
Date: Oct, 30, 2023
Stata Version 14.0
Operating System: Micrsoft Windows 10
*/

clear
set more off
capture log close

*-------------------------------Table 2------------------------------------*
use "investigation_2013_2016.dta" ,clear

*column (1)-(2)
hetprobit lm ability connectionc_yes jiao1_a_yes xs_2014 xs_2015 xs_2016 college_onjob_yes mini_nat gender,het(ability jiao1_a_yes) cluster(location)
hetprobit lm ability connectionc jiao1_a xs_2014 xs_2015 xs_2016 college_onjob_yes mini_nat gender ,het(ability jiao1_a) nolog cluster(location)

use "investigation_2013_2021.dta" ,clear

*column (3)-(4)
hetprobit lm ability connectionc_yes jiao1_a_yes xs_2014 xs_2015 xs_2016 xs_2017 xs_2018 xs_2019 xs_2020 xs_2021 college_onjob_yes mini_nat gender year2014 year2015 year2016 year2017 year2018 year2019 year2020 year2021, het(ability jiao1_a_yes connectionc_yes) cluster(location)
hetprobit lm ability connectionc jiao1_a xs_2014 xs_2015 xs_2016 xs_2017 xs_2018 xs_2019 xs_2020 xs_2021 college_onjob_yes mini_nat gender year2014 year2015 year2016 year2017 year2018 year2019 year2020 year2021, het(ability jiao1_a_yes connectionc) cluster(location)

*calculate marginal effects in column (1):
use "investigation_2013_2016.dta" ,clear
gen ability_int=int(ability*100)/100
hetprobit lm ability_int connectionc_yes jiao1_a_yes xs_2014 xs_2015 xs_2016 college_onjob_yes mini_nat gender, het(ability jiao1_a_yes) cluster(location)
margins, dydx(ability_int) at(ability_int=(-0.09(0.01)0.10))  //calculate marginal effects of capability=1.32
margins, dydx(connectionc_yes)  //calculate marginal effects of connection=-0.07
probit lm ability connectionc_yes jiao1_a_yes xs_2014 xs_2015 xs_2016 college_onjob_yes mini_nat gender, cluster(location)
inteff lm ability connectionc_yes jiao1_a_yes xs_2014 xs_2015 xs_2016 college_onjob_yes mini_nat gender, savedata("interaction_effect_2_1",replace) savegraph1("interaction_effect1_2_1_1",replace) savegraph2("interaction_effect_2_1_2",replace)
*Average marginal effect of interaction:
*egen x=mean(_probit_ie) //x=-0.53

*calculate marginal effects in column (2):
use "investigation_2013_2016.dta" ,clear
hetprobit lm ability connectionc jiao1_a xs_2014 xs_2015 xs_2016 college_onjob_yes mini_nat gender, het(ability jiao1_a) nolog cluster(location)
margins, dydx(ability)   //calculate marginal effects of capability=1.08
margins, dydx(connectionc) at(connectionc=(0(1)26))  //calculate marginal effects of connection=-0.01
probit lm ability connectionc jiao1_a xs_2014 xs_2015 xs_2016 cpc college_onjob_yes mini_nat gender, nolog cluster(location)
inteff lm ability connectionc jiao1_a xs_2014 xs_2015 xs_2016 cpc college_onjob_yes mini_nat gender, savedata("interaction_effect_2_2",replace) savegraph1("interaction_effect1_2_2_1",replace) savegraph2("interaction_effect_2_2_2",replace)
*Average marginal effect of interaction:
*egen x=mean(_probit_ie) //x=-0.25

*calculate marginal effects in column (3):
use "investigation_2013_2021.dta" ,clear
gen ability_int=int(ability*100)/100
hetprobit lm ability_int connectionc_yes jiao1_a_yes xs_2014 xs_2015 xs_2016 xs_2017 xs_2018 xs_2019 xs_2020 xs_2021 college_onjob_yes mini_nat gender year2014 year2015 year2016 year2017 year2018 year2019 year2020 year2021, het(ability jiao1_a_yes connectionc_yes) cluster(location)
margins, dydx(ability_int) at(ability_int=(-0.09(0.01)0.10))  //calculate marginal effects of capability=1.21
margins, dydx(connectionc_yes)  //calculate marginal effects of connection=-0.03
probit lm ability connectionc_yes jiao1_a_yes xs_2014 xs_2015 xs_2016 xs_2017 xs_2018 xs_2019 xs_2020 xs_2021 college_onjob_yes mini_nat gender year2014 year2015 year2016 year2017 year2018 year2019 year2020 year2021, nolog cluster(location)
inteff lm ability connectionc_yes jiao1_a_yes xs_2014 xs_2015 xs_2016 xs_2017 xs_2018 xs_2019 xs_2020 xs_2021 college_onjob_yes mini_nat gender year2014 year2015 year2016 year2017 year2018 year2019 year2020 year2021, savedata("interaction_effect_2_3",replace) savegraph1("interaction_effect1_2_3_1",replace) savegraph2("interaction_effect_2_3_2",replace)
*Average marginal effect of interaction:
*egen x=mean(_probit_ie) //x=-0.78


*calculate marginal effects in column (4):
use "investigation_2013_2021.dta" ,clear
gen ability_int=int(ability*100)/100
hetprobit lm ability_int connectionc jiao1_a xs_2014 xs_2015 xs_2016 xs_2017 xs_2018 xs_2019 xs_2020 xs_2021 college_onjob_yes mini_nat gender year2014 year2015 year2016 year2017 year2018 year2019 year2020 year2021, het(ability jiao1_a_yes connectionc) cluster(location)
margins, dydx(ability_int) //calculate marginal effects of capability=0.87
margins, dydx(connectionc) //calculate marginal effects of connection=-0.01
margins, dydx(jiao1_a)  //Average marginal effect of interaction=-0.48




